<script>

import axios from "axios";
export default {
    data() {
        return {
            imgSrc:localStorage.getItem("userPic")
        }
    }
    ,
    methods: {
        handleChange(file) {
            const empid = localStorage.getItem("userId")
            var formData = new FormData();
            formData.append('file', file.raw)
            formData.append('userId', empid)
            axios.post('/user/updateUserImg', formData).then(resp => {
                // this.imgSrc=resp.data
                console.log(resp.data);
                localStorage.setItem("userInfo",JSON.stringify(resp.data))
                localStorage.setItem("userPic",resp.data.avatar)
                location.reload();
                console.log(resp.data.avatar);
            }
            )
        }
    }
}
</script>

<template>
    <div class="aaaaa">
        <img :src="imgSrc" alt="#">
        <el-upload class="upload-demo" action="" :on-change="handleChange">
            <el-button type="success" style="margin-left: 6px;">更换头像</el-button>
        </el-upload>
    </div>
</template>
<style scoped>
img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    
}
.aaaaa{
    margin-left: 150px;
}
.upload-demo{
    position: relative;
    top: -70px;
    left: 120px;
}
</style>

